﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien1.DAO;
using QuanLyThuVien1.BUS;
using QuanLyThuVien1.DTO;

namespace QuanLyThuVien1.GUI
{
    public partial class Fr_NhaXuatBan : Form
    {
        public Fr_NhaXuatBan()
        {
            InitializeComponent();
        }
        public string ChuanHoa(string m_sChuoi)
        {
            if (m_sChuoi == "")
                return m_sChuoi;
            for (int i = 0; i < m_sChuoi.Length - 1; )
            {
                if (m_sChuoi[i] == 32 && m_sChuoi[i + 1] == 32)
                {
                    m_sChuoi = m_sChuoi.Substring(0, i + 1) + m_sChuoi.Substring(i + 2, m_sChuoi.Length - i - 2);
                }
                else
                    i++;
            }
            if (m_sChuoi[0] == 32 && m_sChuoi.Length == 1)
                return "";

            if (m_sChuoi[0] == 32)
                m_sChuoi = m_sChuoi.Substring(1, m_sChuoi.Length - 1);
            if (m_sChuoi[m_sChuoi.Length - 1] == 32)
                m_sChuoi = m_sChuoi.Substring(0, m_sChuoi.Length - 1);
            return m_sChuoi;
        }

        private void bt_Them_Click(object sender, EventArgs e)
        {
            try
            {
                if (ChuanHoa(tb_maNXB.Text) == "" || ChuanHoa(tb_soDT.Text) == "")
                    MessageBox.Show("Bạn Nhập còn Thiếu Thông Tin", "Thông Báo");
                else
                {
                    CNhaXuatBan_Bus n = new CNhaXuatBan_Bus();
                    NHAXUATBAN n1 = new NHAXUATBAN();
                    n1.DIENTHOAI = tb_soDT.Text;
                    n1.MANXB = tb_maNXB.Text;
                    n1.TENNXB = tb_tenNXB.Text;
                    n.ThemNhaXuatBan(n1);
                    MessageBox.Show("Đã Thêm xong", "Thông Báo");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void bt_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}